package Kuaishou;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.xml.crypto.Data;

/**
 * @author leiwenkang <leiwenkang@kuaishou.com>
 * Created on 2021-03-31
 */
public class Test30TimeUtil {
    private static final SimpleDateFormat YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");

    public static void main(String[] args) {
        Date date = new Date(new Date().getTime() + 60000);
        System.out.println(getDateStr(date));
        System.out.println(getHourOfDay(date));
    }

    /**
     * 获取前dayNum（负数）或者后dayNum(正数）天的日期
     * @return
     */
    public static String getDateStr(Date date) {
        return YYYY_MM_DD.format(date);
    }

    /**
     * 功能描述：返回小时
     *
     * @param date 日期
     * @return 返回小时
     */
    public static int getHourOfDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }
}
